home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / overm82.zip / MSG2TXT.ZIP / MSG2TXT.BAS next >
BASIC Source File  |  1990-01-16  |  5KB  |  194 lines

  1. DECLARE SUB Prints (A$, num.returns%)
  2. DECLARE SUB Print1 (A$)
  3. DECLARE SUB Trim (A$)
  4.  
  5. ' MSG2TXT.BAS
  6. '------------------------------------------------------------------------
  7. '
  8. '  Program to convert a RBBS Messages file to text format
  9. '
  10. '   Tom Collins
  11. '   01-15-90
  12. '
  13.  
  14. '$INCLUDE: 'c:qb.bi'
  15.  
  16. CONST TRUE = -1
  17. CONST FALSE = 0
  18.  
  19. DEFINT A-Z
  20. TYPE Checkpoint                ' RBBS checkpoint message record
  21.    LastMsgNum AS STRING * 8    ' high message number on the system
  22.    AutoAddSec AS STRING * 2
  23.    CallerNum AS STRING * 10
  24.    Reserved1 AS STRING * 36
  25.    NumUserRecsUsed AS STRING * 5
  26.    Reserved2 AS STRING * 6
  27.    FirstRec AS STRING * 7      ' first messages record that contains a message
  28.    NextAvailRec AS STRING * 7  ' next messages record that can be written to
  29.    LastRec AS STRING * 7       ' last record in messages file
  30.    MaxNumMsgs AS STRING * 7    ' max # of messages this file can handle
  31.    Reserved3 AS STRING * 31
  32.    NumNodes AS STRING * 2
  33. END TYPE
  34. TYPE Header                    ' RBBS message header record
  35.    ReadOnly AS STRING * 1
  36.    MsgNumber AS STRING * 4
  37.    MsgFrom AS STRING * 31
  38.    MsgTo AS STRING * 22
  39.    Time AS STRING * 8
  40.    Reserved AS STRING * 1
  41.    Date AS STRING * 8
  42.    MsgSubject AS STRING * 25
  43.    Password AS STRING * 15
  44.    Active AS STRING * 1
  45.    RecsInMsg AS STRING * 4
  46.    MinSecToRead AS STRING * 2
  47.    DateLastRead AS STRING * 3
  48.    TimeLastRead AS STRING * 3
  49. END TYPE
  50. TYPE Text
  51.    MsgTxt AS STRING * 128
  52. END TYPE
  53.  
  54.       DIM Chkpt AS Checkpoint
  55.       DIM Hdr AS Header
  56.       DIM T AS Text
  57.  
  58.       RBBS.Eol$ = CHR$(227)
  59.  
  60.       ON ERROR GOTO 9999
  61.  
  62.       A$ = COMMAND$
  63.       CALL Trim(A$)
  64.       I = INSTR(A$, " ")
  65.       IF (LEN(A$) = 0 OR I = 0) THEN
  66.      PRINT "Usage: Messages_File_Name Text_File_Name"
  67.      END
  68.       ELSE
  69.      Messages.File$ = LEFT$(A$, I)
  70.      Text.File$ = MID$(A$, I)
  71.      CALL Trim(Messages.File$)
  72.      CALL Trim(Text.File$)
  73.       END IF
  74.  
  75. 90    OPEN "CONS:" FOR OUTPUT AS #1
  76.  
  77.       CALL Prints("MSG2TXT v0.01 01-15-90 - Super Dooper RBBS Message to Text Converter", 2)
  78.       CALL Prints("Input File : " + Messages.File$, 1)
  79.       CALL Prints("Output File: " + Text.File$, 2)
  80.  
  81. 100   OPEN "R", 3, Messages.File$, 128
  82. 101   OPEN Text.File$ FOR OUTPUT AS #2
  83.  
  84. 102   GET 3, 1, Chkpt
  85.       First.Rec = VAL(Chkpt.FirstRec)
  86.       Last.Rec = VAL(Chkpt.LastRec)
  87.       Next.Avail.Rec = VAL(Chkpt.NextAvailRec)
  88.  
  89.       I = First.Rec
  90.  
  91.       Msgs.Processed = 0
  92.       Recs.to.Process = Next.Avail.Rec - First.Rec
  93.       CALL Prints("Records to Process:" + STR$(Recs.to.Process), 1)
  94.       Recs.Processed = 0
  95.  
  96.       Lines.Printed = 0
  97.       CALL Print1(CHR$(12) + "MSG2TXT Conversion: " + Messages.File$ + " -> " + Text.File$)
  98.       CALL Print1("  Converted: " + DATE$ + " " + TIME$)
  99.       CALL Print1("")
  100.       CALL Print1("")
  101.  
  102.       DO
  103. 103      GET 3, I, Hdr
  104.      recs.in.msg = VAL(Hdr.RecsInMsg)
  105.      IF recs.in.msg <= 0 THEN
  106.         recs.in.msg = 1
  107.      END IF
  108.      CALL Print1(" Msg #: " + Hdr.ReadOnly + Hdr.MsgNumber)
  109.      CALL Print1("  From:  " + Hdr.MsgFrom + " Sent:  " + Hdr.Date + " " + LEFT$(Hdr.Time, 5))
  110.      CALL Print1("    To:  " + Hdr.MsgTo + SPACE$(9) + " Rcvd:  -NO-")
  111.      CALL Print1("  Subj:  " + Hdr.MsgSubject)
  112.      CALL Print1("")
  113.      One.Line$ = ""
  114.      Txt$ = ""
  115.      FOR J = 1 TO recs.in.msg
  116. 104         GET 3, I + J, T
  117.         Txt$ = Txt$ + MID$(T.MsgTxt, 1, 128)
  118.      NEXT
  119.      k = INSTR(Txt$, RBBS.Eol$)
  120.      IF k = 0 THEN
  121.         CALL Print1("")
  122.      ELSE
  123.         DO WHILE k <> 0
  124.            One.Line$ = LEFT$(Txt$, k - 1)
  125.            IF LEFT$(One.Line$, 1) <> CHR$(1) AND LEFT$(One.Line$, 8) <> "SEEN-BY:" THEN
  126.           CALL Trim(One.Line$)
  127.           CALL Print1(One.Line$)
  128.           One.Line$ = ""
  129.            END IF
  130.            Txt$ = MID$(Txt$, k + 1)
  131.            k = INSTR(Txt$, RBBS.Eol$)
  132.         LOOP
  133.         One.Line$ = Txt$
  134.      END IF
  135.      CALL Print1("")
  136.      I = I + recs.in.msg
  137.      Msgs.Processed = Msgs.Processed + 1
  138.      Recs.Processed = Recs.Processed + recs.in.msg
  139.      CALL Prints(STR$(Msgs.Processed) + " Msgs " + STR$(Recs.Processed) + " Recs" + CHR$(13), 0)
  140.       LOOP WHILE I < Next.Avail.Rec
  141.       CALL Prints("Done Processing                 ", 1)
  142.       CLOSE
  143.       END
  144.  
  145. 9999  PRINT
  146.       SELECT CASE ERL
  147.       CASE 100
  148.      A$ = "Error opening Messages File '" + Messages.File$ + "'"
  149.       CASE 101
  150.      A$ = "Error opening Text File '" + Text.File$ + "'"
  151.       CASE 102, 103, 104
  152.      A$ = "Error Reading Messages File"
  153.       END SELECT
  154.  
  155.       A$ = A$ + " - Program Aborted"
  156.       PRINT A$
  157.       CLOSE
  158.       END
  159.  
  160. SUB Print1 (A$)
  161. '
  162. ' Prints a string on the screen through the "CON" device
  163. '
  164.        SHARED Lines.Printed
  165.        PRINT #2, A$
  166.        Lines.Printed = Lines.Printed + 1
  167.        IF Lines.Printed = 60 THEN
  168.       Lines.Printed = 0
  169.       PRINT #2, CHR$(12);    ' Form feed
  170.       PRINT #2,
  171.       PRINT #2,
  172.       PRINT #2,
  173.        END IF
  174. END SUB
  175.  
  176. SUB Prints (A$, num.returns)
  177. '
  178. ' Prints a string on the screen through the "CON" device
  179. '
  180.        PRINT #1, A$;
  181.        FOR I = 1 TO num.returns
  182.       PRINT #1,
  183.        NEXT I
  184. END SUB
  185.  
  186. SUB Trim (A$)
  187. '
  188. ' Removes left and right spaces from a string
  189. '
  190.        A$ = LTRIM$(A$)
  191.        A$ = RTRIM$(A$)
  192. END SUB
  193.  
  194.